﻿using System;
using System.Collections.Generic;
using Ur;

using Pixels.Logic;

namespace Pixels.Rendering
{
    class Camera
    {

        public float zoom;
        public float zoomGoal;

        public float minZoom = 1.0f;
        public float maxZoom = 2.0f;

        public const float FACTOR = 128f;


        public crds2 project(crds3 worldCoords) {
            //return shalf + (coords - worldCoords.flatten ) * FACTOR;

            var transformedX = (worldCoords.x + worldCoords.y - ( this.coords.x + this.coords.y) ) * FACTOR * zoom;
            var transformedY = (worldCoords.y - worldCoords.x - (this.coords.y - this.coords.x) ) * FACTOR / 2 * zoom;
            
            return shalf + new crds2(transformedX, transformedY);
        }

        public crds2 unproject(crds2 screenCoords) {
            //return coords + (shalf - screenCoords) * (1f / FACTOR);

            var unprojectedX = coords.x / 256 - coords.y / 128 + screenCoords.x + screenCoords.y / 2;
            var unprojectedY = 1;// coords.x / 256 + coords.y / 128 + screenCoords.y / 2;

            return new crds2(unprojectedX, unprojectedY);


        }

        public crds2 coords;
        public crds2 target;

        void doStuff() {           
        }

        crds2 shalf;

        public Camera() {
            shalf = new crds2(Sargon.Screen.w2, Sargon.Screen.h2);
            zoom = minZoom;
            zoomGoal = minZoom;

            target = coords = new crds2(50, 50);            
        }

    }

    //struct ProjectionResult { 
    //    public crds2 coords;
    //    public float scale;        

    //    public ProjectionResult (crds2 coords, float scale)
    //    {
    //        this.coords = coords;
    //        this.scale = scale;
    //    }
    //}
}
